package com.longteng.diamond;

import com.longteng.diamond.domain.BuildTest;
import com.longteng.diamond.domain.Metric;
import com.longteng.diamond.service.IndexService;
import com.longteng.diamond.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator
 * DATE : 2018/6/3
 * TIME : 0:01
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Controller
public class MainController {
    @Autowired
    IndexService indexService;
    @RequestMapping(path = {"/","/index"})
    public ModelAndView index(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("index");
        modelAndView.addObject("queeNotice","更新了");
        /**
         * 获取当前项目所有的用例数量、接口数量、构建次数、用户量
         * **/
        Integer projectId=SessionUtil.getSessionUser().getLastProjectId();
        Metric metric=indexService.getMetric(projectId);
        modelAndView.addObject("metric",metric);

        /**
         * 执行的用例趋势图
         * **/
        List<BuildTest> buildTestList =indexService.buildTestRunMetric(projectId);
        modelAndView.addObject("buildTestList",buildTestList);
        /**
         * 执行的构建趋势图
         * **/
        List<Map> buildTrend=indexService.buildTrend(projectId);
        modelAndView.addObject("buildTrend",buildTrend);
        return modelAndView;
    }
}
